﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UtopianGame.graphics.menu;
using Microsoft.Xna.Framework.Content;

namespace UtopianGame.graphics.menu
{
    class ImplementButton : TextMenuButton
    {
        public ImplementButton(ContentManager cm)
        {
            init(cm);
            message = "Implement";
            boundingBox.Width = ((int)GlobalDataHolder.baseFont.MeasureString(message).X) + 16;
            boundingBox.Height = ((int)GlobalDataHolder.baseFont.MeasureString(message).Y) + 16;
        }

        protected override void init(ContentManager cm)
        {
            base.init(cm);
        }
        protected override void executeFunction()
        {
            GraphicalObject parentType = this.getParentObject();
            if (parentType is PolicyScreen)
            {
                PolicyScreen parentScreen = (PolicyScreen)this.getParentObject();
                int currentPolicyNumber = parentScreen.currentPolicy;

                if (Nation.moneyInTreasury >= Nation.policyList[currentPolicyNumber].xmlData.implementationCost)
                {
                    Nation.policyList[currentPolicyNumber].implement();
                    GlobalDataHolder.removeGraphicalObject(this.getParentObject());
                }
            }
            else if (parentType is InfrastructureScreen)
            {
                InfrastructureScreen parentScreen = (InfrastructureScreen)this.getParentObject();
                int currentInfrastructureNumber = parentScreen.currentInfrastructure;

                if (Nation.moneyInTreasury >= GlobalDataHolder.infrastructureArray[currentInfrastructureNumber].xmlData.buildCost)
                {
                    GlobalDataHolder.infrastructureArray[currentInfrastructureNumber].build();
                    GlobalDataHolder.removeGraphicalObject(this.getParentObject());
                }
            }

        }
    }
}
